package rsj.api.org;

import com.rlyy.aibase.db.Dbink;
import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.ThinkException;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.db.PostgresqlConn;
import rsj.log.ModuleEnum;
import rsj.log.OperationLog;
import rsj.log.OperationTypeEnum;
import rsj.service.OrgService;

import java.sql.Connection;
import java.sql.SQLException;
@RestController
public class OrgInsert extends BaseLink{
	private static OrgService orgInfoService = OrgService.getInstance();

	@RequestMapping(value = "rsj_operative_insert")
	@OperationLog(description = "添加机构", logType = OperationTypeEnum.ADD, logModule = ModuleEnum.INSTITUTIONAL_MANAGEMENT)
	public Box executeLink(Box in) throws ThinkException {

		MapNode data = in.getMapNode("data");

		Connection conn = PostgresqlConn.getConnection();

		try {
			orgInfoService.orgInsert(conn, data, BoxUtil.getTid(in));
		} catch (SQLException e) {
			logger.error("invoke--->" + in.getApi() + " error "
                    + ", arguments is " + in.toJson() , e);
            //return BoxUtil.errorBox(in,  "错误原因::" + e.getMessage());
            return BoxUtil.errorBox(in,  "服务器忙！" );
		}finally {
            Dbink.close(conn);
        }

		return BoxUtil.successBox(in, "添加成功！");
	}


}
